//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.Test.Model {
    public class TestSettings : Eas.WebCrawler.Interfaces.WebCrawlerSettings {

        private IComparer<Eas.WebCrawler.Interfaces.Request> _RequestPriorityComparer = new Eas.WebCrawler.PlugIns.RequestComparers.AlphabeticComparer();

        public IComparer<Eas.WebCrawler.Interfaces.Request> RequestPriorityComparer {
            get { return _RequestPriorityComparer; }
            set { _RequestPriorityComparer = value; }
        }

        /// <summary>LinkExtractor</summary>
        /// <remarks>Backing field for the LinkExtractor property.</remarks>
        /// <seealso cref="LinkExtractor"/>
        private Eas.WebCrawler.Interfaces.LinkExtractor _LinkExtractor = new Eas.WebCrawler.PlugIns.LinkExtractors.HtmlLinkExtractor();

        /// <summary>LinkExtractor</summary>
        public Eas.WebCrawler.Interfaces.LinkExtractor LinkExtractor {
            get { return _LinkExtractor; }
            set { _LinkExtractor = value; }
        }

        /// <summary>Worker Count</summary>
        /// <remarks>Backing field for the WorkerCount property.</remarks>
        /// <seealso cref="WorkerCount"/>
        private int _WorkerCount = 1;

        /// <summary>Worker Count</summary>
        public int WorkerCount {
            get { return _WorkerCount; }
            set { _WorkerCount = value; }
        }

        /// <summary>Starting Uris</summary>
        /// <remarks>Backing field for the StartingUris property.</remarks>
        /// <seealso cref="StartingUris"/>
        private IEnumerable<string> _StartingUris = new string[] { "http://www.google.com", "http://www.yahoo.com" };

        /// <summary>Starting Uris</summary>
        public IEnumerable<string> StartingUris {
            get { return _StartingUris; }
            set { _StartingUris = value; }
        }

        /// <summary>Link Selector</summary>
        /// <remarks>Backing field for the LinkSelector property.</remarks>
        /// <seealso cref="LinkSelector"/>
        private Eas.WebCrawler.Interfaces.LinkSelector _Selector = new Eas.WebCrawler.PlugIns.Selectors.ConstantSelector(true);

        /// <summary>Link Selector</summary>
        public Eas.WebCrawler.Interfaces.LinkSelector Selector {
            get { return _Selector; }
            set { _Selector = value; }
        }

        /// <summary>Storage Factory</summary>
        /// <remarks>Backing field for the StorageFactory property.</remarks>
        /// <seealso cref="StorageFactory"/>
        private Eas.WebCrawler.Interfaces.TemporaryStorageFactory _StorageFactory = new Eas.WebCrawler.PlugIns.TemporaryStorage.MemoryStorageFactory();

        /// <summary>Storage Factory</summary>
        public Eas.WebCrawler.Interfaces.TemporaryStorageFactory StorageFactory {
            get { return _StorageFactory; }
            set { _StorageFactory = value; }
        }

        /// <summary>Completed Request History</summary>
        /// <remarks>Backing field for the CompletedRequestHistory property.</remarks>
        /// <seealso cref="CompletedRequestHistory"/>
        private Eas.WebCrawler.Interfaces.CompletedRequestHistory _CompletedRequestHistory = new Eas.WebCrawler.PlugIns.Histories.AlwaysEmptyRequestHistory();

        /// <summary>Completed Request History</summary>
        public Eas.WebCrawler.Interfaces.CompletedRequestHistory CompletedRequestHistory {
            get { return _CompletedRequestHistory; }
            set { _CompletedRequestHistory = value; }
        }

        /// <summary>SleepTime</summary>
        /// <remarks>Backing field for the SleepTimeInMilliseconds property.</remarks>
        /// <seealso cref="SleepTimeInMilliseconds"/>
        private int _SleepTimeInMilliseconds = 3000;

        /// <summary>SleepTime</summary>
        public int SleepTimeInMilliseconds {
            get { return _SleepTimeInMilliseconds; }
            set { _SleepTimeInMilliseconds = value; }
        }

        /// <summary>Timeout</summary>
        /// <remarks>Backing field for the TimeoutInMilliseconds property.</remarks>
        /// <seealso cref="TimeoutInMilliseconds"/>
        private int _TimeoutInMilliseconds = 5000;

        /// <summary>Timeout</summary>
        public int TimeoutInMilliseconds {
            get { return _TimeoutInMilliseconds; }
            set { _TimeoutInMilliseconds = value; }
        }

        public void Initialize(Eas.WebCrawler.Interfaces.WebCrawlerContext context) {
            context.Events.TraceLevel = Eas.WebCrawler.Interfaces.TraceLevel.Detailed;
            context.Events.OnTrace += new EventHandler<Eas.WebCrawler.Interfaces.ProcessingStateMessageEventArgs>(Events_OnTrace);
            context.Events.OnError += new EventHandler<Eas.WebCrawler.Interfaces.ProcessingStateMessageEventArgs>(Events_OnError);
        }

        void Events_OnError(object sender, Eas.WebCrawler.Interfaces.ProcessingStateMessageEventArgs e) {
            System.Diagnostics.Debug.Write("ERROR:\t");
            //System.Diagnostics.Debug.WriteLine(e.Message);
        }

        void Events_OnTrace(object sender, Eas.WebCrawler.Interfaces.ProcessingStateMessageEventArgs e) {
            //System.Diagnostics.Debug.WriteLine(e.Message);
        }
    }
}
